/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __SOUNDEFFECT_OPENAL_H__
#define __SOUNDEFFECT_OPENAL_H__

#pragma once
#include "al/al.h"
#include "AbstractSound_OpenAL.h"
#include <vector> 

namespace openAL {

class SoundBuffer_OpenAL;


class DLL_EXPORT SoundEffect_OpenAL :
	public openAL::AbstractSound_OpenAL
{
public:
	
	SoundEffect_OpenAL(SoundBuffer_OpenAL* pSoundBuffer);	
	virtual ~SoundEffect_OpenAL(void);
	
	/**
	*	Start sound
	*/
	virtual bool play();

	/**
	*	Start ths sound by fading in.
	*	\param float fFadeTime
	*	!!! Not supported by this class !!!
	*/
	virtual bool play_fadeIn(float fFadeTime){return false;};

	
	/**
	*	Stop sound
	*/
	virtual void stop();

	/**
	*	Fade out the sound and stop it afterwards.
	*	\param float fFadeOutTime
	*
	*	!!! Not used by Soundeffect_openAL !!!	
	*/
	virtual void fadeAndStop(float fFadeTime){};

	virtual void setNumVoices(int _val);
	
	/*
	*	Get the state of the ISound:
	*	ISOUND_PLAYING, ISOUND_STOPPED...
	*/
	virtual int getState();

	/*
	*	Update loop. Should only be called, when sound is playing
	*/
	virtual void update(const double &dt);

	/**
	*	Set m_sourceID to NULL;
	*	!!! We deal with multiple sources
	*/
	virtual void stealSource(ALuint _source);
			
protected:
	
	SoundBuffer_OpenAL * m_pSoundBuffer; ///< The abstract soundData from which the Sound is played.

	// Used when playing a sound multiple	
	typedef std::vector<ALuint> SourceVec;
	SourceVec m_vSources;

	int m_iNumVoices;
};

} // namespace openAL

#endif // __SOUNDEFFECT_OPENAL_H__
